const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}


// 显示繁忙提示
var showBusy = text => wx.showToast({
    title: text,
    icon: 'loading',
    duration: 10000
})

// 显示成功提示
var showSuccess = text => wx.showToast({
    title: text,
    icon: 'success'
})

// 显示失败提示
var showModel = (title, content) => {
    wx.hideToast();

    wx.showModal({
        title,
        content: JSON.stringify(content),
        showCancel: false
    })
}
//正则判断
function Regular(str, reg) {
    if (reg.test(str))
        return true;
    return false;
}

//是否为中文
function IsChinese(str) {
    var reg = /^[\u0391-\uFFE5]+$/;
    return Regular(str, reg);
}
//去左右空格;
function trim(s){
    return s.replace(/(^\s*)|(\s*$)/g, "");
}


 function isNUll(value) {
    if (value == null || value == undefined) return true
    if (judgeString(value)) {
        if (value.trim().length == 0) return true
    } else if (judgeArray(value)) {
        if (value.length == 0) return true
    } else if (judgeObject(value)) {
        for (let name in value) return false
        return true
    }
    return false;
}
function judgeString(value) {
    return value != null && value != undefined && value.constructor == String
}
function judgeNumber(value) {
    return value != null && value != undefined && value.constructor == Number
}
function  judgeBoolean(value) {
    return value != null && value != undefined && value.constructor == Boolean
}
function judgeArray(value) {
    return value != null && value != undefined && value.constructor == Array
}
function judgeObject(value) {
    return value != null && value != undefined && value.constructor == Object
}
function judgeFunction(value) {
    return value != null && value != undefined && value.constructor == Function
}



module.exports = { formatTime, showBusy, showSuccess, showModel,isNUll}
